<?

if (!$_POST['client']){$_POST['client']=$_GET['search'];}
$ligne=FALSE;

if ($_GET['tri'])
{
$order="ORDER BY ".$_GET['tri'];
}
else
{
$order="ORDER BY nom, prenom, societe";
}
if (0<$_POST['client'] && 9999999999999>$_POST['client'])
	{
	$sql="SELECT * FROM contacts WHERE ean='".$_POST['client']."' ".$order;
	}
else
	{
	$sql="SELECT * FROM contacts WHERE nom LIKE '%".$_POST['client']."%' OR prenom LIKE '%".$_POST['client']."%' OR societe LIKE '%".$_POST['client']."%' ".$order;
	}


$res=mysql_query($sql,$db);
?>
<table border="0">
<tr>
<td><a href="?client_tri=1&tri=societe&search=<?= $_POST['client'] ?>">Société</a></td>
<td><a href="?client_tri=1&tri=nom&search=<?= $_POST['client'] ?>">Nom</a></td>
<td><a href="?client_tri=1&tri=prenom&search=<?= $_POST['client'] ?>">Prénom</a></td>
<td>&nbsp;</td>
</tr>
<?
while($ligne=mysql_fetch_object($res))
	{
	
	$img="cpt_jaune_25.gif";
	if ($ligne->solde_en_notre_faveur<0){$img="cpt_vert_25.gif";}
	elseif($ligne->solde_en_notre_faveur>0) {$img="cpt_rouge_25.gif";}
	?>
  <tr><td width="150" bgcolor="#DDDDDD"><?= $ligne->societe ?></td>
	<td width="150" bgcolor="#DDDDDD"><?= $ligne->nom ?></td>
	<td width="150" bgcolor="#DDDDDD"><?= $ligne->prenom ?></td>
	<td><a href="?client_found=<?= $ligne->id ?>"><img src="../images/fleche_ve_dr25.gif" border="0"></a>
	<? print mklink_simple("pop.form.edit_contact.php?id=$ligne->id", 765, 700, 10, 10, "Ed") ?> <img src="../images/switch_info25.gif" alt="Editer" border=0></a><a href="print.client.php?id=<?= $ligne->id ?>" target=_blank><img src="../images/printer25.gif" alt="version imprimable" border=0></a>
  <a href="?compta_compte=105<?= $ligne->id ?>"><img src="../images/<?= $img ?>" border=0></a></td>
  </tr>
	<?
	}
	$_SESSION['client_search']=$_POST['client'];
?> 
</table>